package LC;
public class LC61 {
    public ListNode rotateRight(ListNode head, int k) {
        if (k == 0 || head == null || head.next == null) {
            return head;
        }
        ListNode ter=head;
        int n=1;
        while(ter.next!=null){
            ter=ter.next;
            n++;
        }
        int num=n-k%n;
        if(num==n){
            return head;
        }
        ter.next=head;//连接成环
        while(num-->0){
            ter=ter.next;
        }
        ListNode res=ter.next;
        ter.next=null;//拆分开
        return res;
    }
    public static void print(ListNode head){
        while(head!=null){
            System.out.print(head.val+"->");
            head=head.next;
        }
    }

}
